package com.soft.face.global;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {


    /**
     * 自定义异常
     */
    @ExceptionHandler(BusinessException.class)
    public R<?> businessException(BusinessException e) {
        log.error(e.getMessage(), e);
        R<?> r = new R<>();
        r.setCode(e.getCode());
        r.setMessage(e.getMessage());
        return r;
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public R<?> handleIllegalArgumentException(IllegalArgumentException e) {
        log.error(e.getMessage(), e);
        R<?> r = new R<>();
        r.setCode(ErrorCodeEnum.PARAM_ERROR.getCode());
        r.setMessage(e.getMessage());
        return r;
    }

    @ExceptionHandler(Exception.class)
    public R<?> handleException(Exception e) {
        log.error(e.getMessage(), e);
        R<?> r = new R<>();
        r.setCode(ErrorCodeEnum.SYSTEM_ERROR.getCode());
        r.setMessage(ErrorCodeEnum.SYSTEM_ERROR.getMessage());
        return r;
    }




}
